package com.candy.control;

import com.candy.dao.DBHelper;
import com.candy.modal.UserLoginModal;
import com.candy.pojo.users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UserRegister")
public class UserRegister extends HttpServlet {
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String userName= request.getParameter("userName");
        String userPwd= request.getParameter("userPwd");
        String airName=request.getParameter("airName");
        String phone=request.getParameter("phone");
        String address=request.getParameter("address");
        System.out.println("注册的用户名："+userName+"，注册的密码："+userPwd);
        UserLoginModal userM=new UserLoginModal();
        String strSql="select * from users where uid='"+userName+"' and pwd='"+userPwd+"'";
        boolean isok=userM.isLogined(strSql);
        users user=new users(userName,userPwd,airName,phone,address);
        String strSql1 = "INSERT INTO users(uid,pwd,airname,phone,address) VALUES(?,?,?,?,?);";
        DBHelper db=new DBHelper();
        db.adduser(user,strSql1);
        request.getRequestDispatcher("login.jsp").forward(request,response);

    }
}
